<?php


class PokaYokeString extends PokaYokeRetriever
{
	public function retrieve( $options )
	{
     	if ( is_string( $this->value ) ) {
			// Quotes checking
			if ( isset( $options[ 'quote' ] ) && $options[ 'quote' ] === true ) {
    	    	if ( ! isset( $options[ 'quoteType' ] ) ) {
                    $options[ 'quoteType' ] = "'";
				}

				$this->value = $options[ 'quoteType' ]
				. str_replace( $options[ 'quoteType' ], "\\" . $options[ 'quoteType' ], $this->value )
				. $options[ 'quoteType' ];
			}

			// Minimum Length checking
			if ( isset( $options[ 'minLength' ] ) && $options[ 'minLength' ] >= strlen( $this->value ) ) {
            	throw new PokaYokeException(
					"Current value [ " . $this->value . " ] (" . strlen( $this->value ) . " chars) "
					."is shorter than minimum length [ " . $options[ 'minLength' ] . " ]"
				);
			}

			// Maximum Length checking
            if ( isset( $options[ 'maxLength' ] ) && $options[ 'maxLength' ] <= strlen( $this->value ) ) {
            	throw new PokaYokeException(
					"Current value [ " . $this->value . " ] (" . strlen( $this->value ) . " chars) "
					. "is larger than maximum length [ " . $options[ 'maxLength' ] . " ]"
				);
			}
			
			return $this->value;
		}
		
		throw new PokaYokeException(
			"Cannot retrieve the value [ type: " . gettype( $this->value ) . " ] into string type"
		);

		return false;
	}
}


?>